<template>
	<view class="content b-t">
		<view class="list b-b" v-for="(item, index) in list" :key="index" @click="navDevice(item)">
			<view class="wrapper">
				<view class="address-box">
					<text v-if="item.default" class="tag">默认</text>
					<text class="address">{{item.customName}}</text>
				</view>
				<view class="u-box">
					<text class="name">家庭住址：{{item.homeAddress}}</text>
				</view>
			</view>
			<text :class="item.anfangSn && item.anfangSn.length > 0 ? 'active':'noactive'">{{item.anfangSn && item.anfangSn.length > 0 ?'已绑定':'未绑定'}}</text>
		</view>
		<text style="display:none;padding: 16upx 30upx 10upx;lihe-height: 1.6;color: #fa436a;font-size: 24upx;">
			重要：添加和修改地址回调仅增加了一条数据做演示，实际开发中将回调改为请求后端接口刷新一下列表即可
		</text>
		
		
	</view>
</template>

<script>
import { getCstmListByUserId } from '@/api/userInfo';	
	export default {
		 data() {
			return {
				list:[]
				
			}
		},
		onLoad() {
			this.userInfo = uni.getStorageSync('userInfo');
			this.getcstmList();
		},
		onPullDownRefresh() {
			this.reload = true;
			this.last_id = '';
			this.getcstmList('refresh');
		},
		onReachBottom() {
			this.status = 'more';
			this.getcstmList();
		},
		methods: {
			navDevice(item) {
				if(item.anfangSn && item.anfangSn.length > 0){
					this.$mRouter.push({
						route: `/pages/zhyl/device/zncd/bed?id=${item.id}&cstmName=${item.customName}`
					});					
					
				}else{
					this.$mHelper.toast('该老人未绑定智能床垫!')
	
				}
			},
			// 获取家人列表
			async getcstmList(type) {
			   var params = {
				page: 1,
				userId: this.userInfo && this.userInfo.userId,
				corpId:this.userInfo && this.userInfo.corpId				
			  }
				await this.$http
					.get(`${getCstmListByUserId}`, params)
					.then(r => {
						this.loading = false;
						if (type === 'refresh') {
							uni.stopPullDownRefresh();
						}
						this.loadingType = r.data.length === 10 ? 'more' : 'nomore';
						this.list = [...this.list, ...r.data];
					})
					.catch(() => {
						this.loading = false;
						if (type === 'refresh') {
							uni.stopPullDownRefresh();
						}
					});
			}
		},
	}
</script>

<style lang='scss'>
	page{
		padding-bottom: 120upx;
	}
	.content{
		position: relative;
	}
	.active {
		color: $uni-color-success;
	}
	.noactive {
		color: $uni-color-error;
	}		
	.list{
		display: flex;
		align-items: center;
		padding: 20upx 30upx;;
		background: #fff;
		position: relative;
	}
	.wrapper{
		display: flex;
		flex-direction: column;
		flex: 1;
	}
	.address-box{
		display: flex;
		align-items: center;
		.tag{
			font-size: 24upx;
			color: $base-color;
			margin-right: 10upx;
			background: #fffafb;
			border: 1px solid #ffb4c7;
			border-radius: 4upx;
			padding: 4upx 10upx;
			line-height: 1;
		}
		.address{
			font-size: 30upx;
			color: $font-color-dark;
		}
	}
	.u-box{
		font-size: 28upx;
		color: $font-color-light;
		margin-top: 16upx;
		.name{
			margin-right: 30upx;
		}
	}
	.icon-bianji{
		display: flex;
		align-items: center;
		height: 80upx;
		font-size: 40upx;
		color: $font-color-light;
		padding-left: 30upx;
	}
	
	.add-btn{
		position: fixed;
		left: 30upx;
		right: 30upx;
		bottom: 16upx;
		z-index: 95;
		display: flex;
		align-items: center;
		justify-content: center;
		width: 690upx;
		height: 80upx;
		font-size: 32upx;
		color: #fff;
		background-color: $base-color;
		border-radius: 10upx;
		box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);		
	}
</style>
